<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>管理阶段</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	
	<link rel="stylesheet" href="css/vivo.css">
	<link rel="stylesheet" href="css/common.css">
	<link rel="stylesheet" href="css/bootstrap.css">
	<link rel="stylesheet" href="js/bootstrap2/css/bootstrap.min.css">
	<link rel="stylesheet" href="css/common.css">
	<link rel="stylesheet" type="text/css" href="js/webuploader-0.1.5/webuploader.css" />
	
	<script src="js/jquery-1.11.1.js"></script>
	<script type="text/javascript" src="js/webuploader-0.1.5/webuploader.js"></script>
	<script type="text/javascript" src="js/sharefunction.js"></script>
	<script type="text/javascript" src="js/layui-v2.1.5/layui/layui.all.js"></script>
	<script type="text/javascript" src="<%=basePath %>js/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="js/form.js"></script>
	<!-- 图片放大 -->
	<script src="js/postbird-img-glass/postbird-img-glass.js"></script>
  </head>
  
  <script type="text/javascript">
	  $(function(){
			//如果已经保存过了，则开启只读状态
			<c:if test="${not empty requestScope.manageStage }">
				$("#manageStage").find("input,textarea").attr("readonly",true);
				$("#manageStage .Wdate").attr("disabled",true);
			</c:if>
			
			initWebUpload("filePicker_jgt", "list_jgt", "竣工图", "manageStage_articleId", manageStageSuccess, manageStageErr);
			//上传按钮添加默认宽高
			$("div[id^='filePicker_'] div").css({
					"width" : "60px",
					"height" : "28px"
				});
			var id = '${manageStage.id}';
			if(id == ""){
	  			//上传按钮水平排列
				$("div[id^='filePicker_']").css({"display":"inline-block","vertical-align":"bottom"});
				$("#manageStage .uploadcancel").show();
	  		}
			getFiles();
			toolTip(true);
	  })
	  //展示附件  
		function getFiles() {
		  getFileListByFlag($("#manageStage #entityId_id").val(), "竣工图", 1,"#list_jgt", setRFL, imgPlus);
		}
	  function imgPlus(data) {
			$("#manageStage .uploadcancel").css("display", "none");
			$.each(data, function(i, v) {
				//图片放大
				PostbirdImgGlass.init({
					domSelector : "#" + v.id + " img",
					animation : true,
					myDocument : window.parent.parent.parent
				});
			});
		}
	  //上传成功回调
		function manageStageSuccess(file, response) {
			PostbirdImgGlass.init({
				domSelector : "td img",
				animation : true,
				myDocument : window.parent.parent.parent
			});
		}
		var rFileList = new Array(); //
		//设置待删除附件的值到集合中
		function setRFL(id, _this) {
			layer.confirm('删除该图片？', {
				title : '警告',
				icon : 0,
				shade : [ 0.1, '#fff' ]
			}, function() {
				rFileList.push(id);
				//rFileList=id+","+rFileList
				//删除指定缩略图
				$("#" + id).remove();
				layer.close(layer.index);
			});
		}
		//上传失败回调
		function manageStageErr(file, data) {
			//alert("上传失败回调");
		}
  </script>
  <body>
  <div style="padding:0px 10px">
  <form id="manageStage" method="post" action="" onsubmit="return false;">
  	<input type="hidden" id="manageStage_articleId">
		<div class="panel panel-default">
			<div class="panel-heading">
      			<h5 class="panel-title">管理阶段</h5>
   			</div>
			<div class="panel-body">
				<table cellpadding="10" cellspacing="5" class="mytable" >
					<tr>
						<td width="70" class="td-right">管理时间</td>
						<td width="260"><input id="manageDate" name="manageDate" readonly="readonly" value="<fmt:formatDate value="${requestScope.manageStage.manageDate }" pattern="yyyy-MM-dd" />" class="Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></td>
						<td width="70" class="td-right">管理单位</td>
						<td><input name="manageUnit" value="${requestScope.manageStage.manageUnit }" class="input_name toolTip"/></td>
					</tr>
					<tr>
						<td class="td-right">审批地名</td>
						<td><input  name="approvalToponymy" class="toolTip" value="${requestScope.manageStage.approvalToponymy }" /></td>
						<td class="td-right">产权所有</td>
						<td><input name="equityOwnership" class="toolTip" value="${requestScope.manageStage.equityOwnership }" /></td>
					</tr>
					<tr>
						<td class="td-right">开始时间</td>
						<td><input  name="staDate" id="staDate" readonly="readonly" class="Wdate" value="<fmt:formatDate value="${requestScope.manageStage.staDate }" pattern="yyyy-MM-dd" />" onClick="WdatePicker({maxDate:'#F{$dp.$D(\'endDate\')}',minDate:'#F{$dp.$D(\'manageDate\')}'})"/></td>
						<td class="td-right">结束时间</td>
						<td><input  name="endDate" id="endDate" readonly="readonly" class="Wdate" value="<fmt:formatDate value="${requestScope.manageStage.endDate }" pattern="yyyy-MM-dd" />" onClick="WdatePicker({minDate:'#F{$dp.$D(\'staDate\')}'})"/></td>
					</tr>
					<tr>
						<td class="td-right">管理范围</td>
						<td colspan="3"><input name="manageScope" class="toolTip" value="${requestScope.manageStage.manageScope }" /></td>
					</tr>
					<tr>
						<td class="td-right">竣工图</td>
						<td colspan="3"><input name="completionMap" id="completionMap" value="${requestScope.manageStage.completionMap }" />
							 <!-- 上传按钮 -->
							<div id='filePicker_jgt' style="display:none;">上传</div>
						</td>
					</tr>
					<tr>
						<td colspan="4">
							<!-- 附件上传 管理阶段———竣工图。。。--> <!-- 缩略图容器 -->
							<div id='list_jgt'></div>
						</td>
					</tr>
				</table>
			</div>
		</div>
		<!-- 修改时添加变更说明 -->
		<div style="margin:10px;" hidden="hidden" id="changeRemark">
			变更说明<textarea rows="3" name="changeRemark"style="width:70%"></textarea><span style="color:red;">*</span>
		</div>
		<input type="hidden" id="entityId_id" name="id" value="${requestScope.manageStage.id }"/>
		<div style="width:100%;text-align:center; padding-top:0px">
			<c:choose>
				<c:when test="${empty requestScope.manageStage }">
					<button class="btn btn-danger radius my-btn"
						onclick="saveManage(0)" type="button">提交</button>
					<button class="btn btn-danger radius my-btn"
						onclick="saveManage(1)" type="button">保 存</button>
					<a class="btn btn-default radius" onClick="resetForms('manageStage');">
						重置 </a>
					<br />
				</c:when>
				<c:otherwise>
					<shiro:hasPermission name="permission:edit">
						<button id="modifyBtn" class="btn btn-danger radius my-btn"
							onclick="saveManage(3)" type="button">启用编辑</button>
						<button class="btn btn-danger radius my-btn hidbtn"
							onclick="saveManage(2)" type="button">保存修改</button>
						<a class="btn btn-default radius hidbtn" onClick="resetForms('manageStage');">
							重置 </a>	
					</shiro:hasPermission> 
				</c:otherwise>
			</c:choose>
		</div>
	</form>
  </div>
  <script type="text/javascript">
  	
	  function saveManage(opt){
			var manageDate=$("input[name='manageDate']").val();
			var manageUnit=$("input[name='manageUnit']").val();
			var approvalToponymy=$("input[name='approvalToponymy']").val();
			var equityOwnership=$("input[name='equityOwnership']").val();
			var staDate=$("input[name='staDate']").val();
			var endDate=$("input[name='endDate']").val();
			var manageScope=$("input[name='manageScope']").val();
			var fkPa=window.parent.$("#fkPa").val();
			var id=$("#manageStage #entityId_id").val();
			var marketId = parent.$("#entityId_marketId").val();
			var changeRemark = $("#manageStage textarea[name='changeRemark']").val();
			var AccessoryCaList = $("#manageStage #manageStage_articleId").val();
			var completionMap=$("#manageStage #completionMap").val();
			if(opt==3){
				var apList = '${apList}';
				if(apList!=null && apList!="" && apList.length>2){
					layer.msg("此条数据已提交过审批，不能重复提交");
				}else{
					//解除锁定状态
					var index=layer.confirm('确定开启编辑状态？', {
					 	offset:'20%',
						shade:0
					}, function(){
					  //去除只读开启按钮编辑
					  //上传按钮水平排列
					   $("div[id^='filePicker_']").css({"display":"inline-block","vertical-align":"bottom"});
					   $("#manageStage #changeRemark").show();
					   $("#manageStage").find("input,textarea").attr("readonly",false);
					   $("#manageStage .Wdate").attr("disabled",false);
					   $("#manageStage #modifyBtn").remove();
					   $("#manageStage .hidbtn").removeClass("hidbtn");
					   $("#manageStage .uploadcancel").show();
					   layer.close(index);
					});
				}
			}else{
				var i = layer.load(2);
				if(id!="" && id!=null && id!=undefined){
					if(changeRemark==""){
						layer.alert("变更说明不能为空");
						layer.close(i);
						return null;
					}
				}
				var url="project/approval/addManage";
				if(id!=""){
					if(changeRemark==""){
						layer.alert("变更说明不能为空");
						layer.close(i);
						return null;
					}
				}
				if(!valLength(50,manageUnit)){
					layer.msg("管理单位名称长度不能超过50");
					$("input[name='manageUnit']").focus();
					layer.close(i);
				}else if(!valLength(50,manageScope)){
					layer.msg("管理范围长度不能超过50");
					$("input[name='manageScope']").focus();
					layer.close(i);
				}else{
					jQuery.ajax({
				    type:"post",
				    async:false,
				    url:url,
			        dataType:"json",
			        traditional: true,
			        data:{
			        	id:id,
			        	fkProjectApproval:fkPa,
			        	manageDate:manageDate,
			        	manageUnit:manageUnit,
			        	approvalToponymy:approvalToponymy,
			        	equityOwnership:equityOwnership,
			        	staDate:staDate,
			        	endDate:endDate,
			        	manageScope:manageScope,
			        	opt:opt,
			        	marketId:marketId,
			        	changeRemark:changeRemark,
			        	AccessoryCaList:AccessoryCaList,
			        	rFileList : rFileList,
			        	completionMap:completionMap
			        },
				    success:function(responseText){
				    	layer.close(i);
				        if(responseText.success){
				        	layer.alert("保存成功！", {
				        		offset:'20%',
				        		shade:[0.1,'#fff']
							}, function() {
								parent.location.reload();
				
							});
			  			}else{
			  				alert(responseText.msg, {icon: 7});
			  				layer.closeAll();
			  			}
				    }
				});
				}
			}
		}
  	
  </script>
  </body>
</html>

